<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="身份证号" prop="s_idnumber">
        <el-input
          v-model="queryParams.s_idnumber"
          placeholder="请输入患者身份证号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>



    <el-form ref="form" :model="form" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="身份证号" prop="s_idnumber">
        <el-input v-model="form.s_idnumber" placeholder="请输入身份证号" style="width: 200px"/>
      </el-form-item>
      <el-form-item label="患者姓名" prop="s_name">
        <el-input v-model="form.s_name" placeholder="请输入患者姓名" style="width: 150px"/>
      </el-form-item>
      <el-form-item label="患者电话" prop="s_phone">
        <el-input v-model="form.s_phone" placeholder="请输入患者电话" style="width: 200px"/>
      </el-form-item>
      <el-form-item label="性别" prop="s_sex">
        <el-input v-model="form.s_sex" placeholder="请输入患者性别" style="width: 140px" />
      </el-form-item>
      <el-form-item label="出生日期" prop="s_birth">
        <el-input v-model="form.s_birth" placeholder="请输入出生日期" style="width: 150px"/>
      </el-form-item>
      <el-form-item label="患者年龄" prop="s_age">
        <el-input v-model="form.s_age" placeholder="请输入患者年龄" style="width: 140px"/>
      </el-form-item>
      <el-form-item label="地址信息" prop="s_address">
        <el-input v-model="form.s_address" placeholder="请输入地址信息" style="width: 350px"/>
      </el-form-item>
    </el-form>


    <el-radio-group v-model="radioGroup1">
      <el-radio-button v-for="city in cities" :label="city" :key="city">{{city}}</el-radio-button>
    </el-radio-group>

    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="所属科室" prop="s_departments">
        <el-select v-model="queryParams.s_departments" placeholder="请选择所属科室" clearable size="small">
          <el-option
            v-for="dict in s_departmentsOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="挂号类型" prop="s_registration">
        <el-select v-model="queryParams.s_registration" placeholder="请选择挂号类型" clearable size="small">
          <el-option
            v-for="dict in s_registrationOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="挂号时段" prop="s_registrationTime">
        <el-select v-model="queryParams.s_registrationTime" placeholder="请选择挂号时段" clearable size="small">
          <el-option
            v-for="dict in s_registrationTimeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table
      :data="roleList"
      border
      style="width: 100%">
      <el-table-column
        prop="s_departmentId"
        label="科室ID"
      >
      </el-table-column>
      <el-table-column
        prop="s_departments"
        label="科室名称"
      >
      </el-table-column>
      <el-table-column
        prop="s_ids"
        label="当前号数">
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
    import { listPost, getPost, delPost, addPost, updatePost, exportPost } from "@/api/visits/register";

    const cityOptions = ['门诊', '门诊+病例本', '急诊', '急诊+病例本'];

    export default {
        name: "Post",
        data() {
            return {
                // 遮罩层
                loading: true,
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                // 岗位表格数据
                postList: [],
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 状态数据字典
                statusOptions: [],
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                    s_idnumber: undefined,
                    s_registrationTime: undefined,
                    s_registration: undefined,
                    s_departments: undefined
                },

                radioGroup1: ['门诊'],
                cities: cityOptions,
                // 挂号类型数据字典
                s_registrationOptions: [],
                //挂号时段数据字典
                s_registrationTimeOptions: [],
                //部门数据字典
                s_departmentsOptions: [],
                // 表单参数
                form: {},
                // 表单校验
                rules: {

                }
            };
        },
        /** 查询角色列表 */
        getList() {
            listPost(this.queryParams).then(response => {
                this.form = response.data;
            });
        },
        created() {
            this.getList();
            this.getDicts("sys_time_status").then(response => {
                this.s_registrationTimeOptions = response.data;
            });
            this.getDicts("sys_registration_type").then(response => {
                this.s_registrationOptions = response.data;
            });
            this.getDicts("sys_department_status").then(response => {
                this.s_departmentsOptions = response.data;
            });
        },
        methods: {
            /** 查询岗位列表 */
            getList() {
                this.loading = true;
                listPost(this.queryParams).then(response => {
                    this.postList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            // 岗位状态字典翻译
            statusFormat(row, column) {
                return this.selectDictLabel(this.statusOptions, row.status);
            },

            // 表单重置
            reset() {
                this.form = {
                    s_idnumber: undefined,
                    s_name: undefined,
                    s_phone: undefined,
                    s_sex: undefined,
                    s_birth: undefined,
                    s_age: undefined,
                    s_address: undefined
                };
                this.resetForm("form");
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.reset();
                const s_idnumber = this.queryParams.s_idnumber
                getPost(s_idnumber).then(response => {
                    this.form = response.data;
                    this.open = true;
                });
            },

        }
    };
</script>
